package bootstrap

import (
	"fmt"

	"github.com/spf13/viper"
	"ttsx/server/common/global"
)

var configFile = "../config/config.yaml"

func InitConfig() *viper.Viper {
	v := viper.New()
	v.SetConfigFile(configFile)
	v.SetConfigType("yaml")

	if err := v.ReadInConfig(); err != nil {
		panic(fmt.Errorf("read config failed: %s \n", err))
	}

	if err := v.Unmarshal(&global.App.Config); err != nil {
		fmt.Println(err)
	}
	return v
}
